package com.shangcheng.search.controller;


import com.shangcheng.orders.feign.CartFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Controller
@RequestMapping("/wcart")
public class CartController {

    @Autowired
    private CartFeign cartFeign;

    //删除
    @GetMapping(value = "/dele")
    public String deleteCart(@RequestParam Long id,
                             @RequestParam String username,
                             Model model) {
        cartFeign.deleteCart(id);
        Map map = cartFeign.list(username);
        model.addAttribute("items", map);
        return "cart";
    }

    //查询
    @GetMapping(value = "/list")
    public String listCart(@RequestParam String username,
                             Model model) {
        Map map = cartFeign.list(username);
        model.addAttribute("items", map);
        return "cart";
    }


    //添加
    @GetMapping(value = "/add")
    public String add(@RequestParam Long id,
                      @RequestParam Integer num,
                      @RequestParam String username,
                      ModelMap model) {
        cartFeign.addCart(id, num, username);
        Map map = cartFeign.list(username);
        model.addAttribute("items", map);
        return "cart";
    }
}
